package cn.controller;

import org.springframework.stereotype.Component;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

@Component
@ServerEndpoint("/ws/{sid}")
public class SocketController {

    @OnOpen
    public void open(@PathParam("sid") String sid){
        System.out.println("客户端："+sid+"  连接成功");
    }

    @OnMessage
    public void message(String message,@PathParam("sid") String sid){
        System.out.println("sid:" + sid);
        System.out.println("客户端发消息："+message);
    }

    @OnClose
    public void close(@PathParam("sid") String sid){
        System.out.println("sid:" + sid);
        System.out.println("客户端退出了");
    }
}
